<?php
include( "agent/onlinebet_header4.php" );
if ($curruser['acl'] != 255)
{
    $userlist = GetUserList($curruser['id']);
    if ($userlist == "")
    {
        $ui->showErrorPage("<p>还没有建立会员！</p>");
        exit();
    }
}
$norder = intval(getvar("norder"));
if (1 > $norder || $norder > 6)
{
    $norder = 1;
}
$g_disk_code = array(1 => "a", 2 => "b", 3 => "c", 4 => "d");
$disk_code = "a";
$diskStr = "";
if (0 < $disk)
{
    $disk_code = $g_disk_code[$disk];
    $diskStr = $disk_code;
}
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h($lotto_id);
$colors = array("", "red", "blue", "green");
$dataTotalArr = array();
$showDataArr = array();
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
switch ($bets)
{
    case 0 :
        $betids = array(1003);
        $bettypeStr = "1003";
        $listbetmod = 88;
        $betsGame = "1003";
        break;
    case 1 :
        $betids = array(25);
        $bettypeStr = "25";
        $listbetmod = 25;
        $betsGame = "25";
        break;
    case 2 :
        $betids = array(26);
        $bettypeStr = "26";
        $listbetmod = 26;
        $betsGame = "26";
        break;
    default :
        $betids = array(1003);
        $bettypeStr = "1003";
        $listbetmod = 88;
        $betsGame = "1003";
        break;
}
$dataTotalArr[$betsGame] = array("bettype" => $betsGame, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
$sql = $BetTotal_6h->getDataListTotalSQL($lotto_id, $bettypeStr, $showid, $split, $diskStr, " AND numbers LIKE '{$norder},%'");
$totalRs = getdb($sql);
while (!$totalRs->eof)
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
$lostwin = array();
$winlost = $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'];
$i = 1;
while ($i < 50)
{
    $showDataArr[$betsGame][$i] = array("numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost, "namount" => "");
    $lostwin[$betsGame][$i] = $winlost;
    ++$i;
}
$sql = $BetTotal_6h->getDataListByNumSsSQL($lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod);
$sql .= " AND numbers LIKE '{$norder},%'";
$rs = getdb($sql);
$updatetime = systime() - 30;
while (!$rs->eof)
{
    $bettype = $rs->f['bettype'];
    $i = intval(substr($rs->f['numbers'], 2));
    $winlost = $dataTotalArr[$bettype]['amount'] - $rs->f['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'];
    $lostwin[$bettype][$i] = $winlost;
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    $showDataArr[$bettype][$i]['back1'] = $rs->f['back1'];
    $showDataArr[$bettype][$i]['back2'] = $rs->f['back2'];
    $showDataArr[$bettype][$i]['winlost'] = $winlost;
    if ($updatetime < $rs->f['updatetime'])
    {
        $showDataArr[$bettype][$i]['namount'] = " class=\"namount\"";
    }
    $rs->next();
}
$rs->close();
if ($ratemod == 0)
{
    $rateIdx = "r";
    if ($bets == 2)
    {
        $rateIdx = "br";
    }
    $rs = getdb("select * from rate4{$norder}{$disk_code} where lotto_id={$lotto_id}");
    if ($theacl == 255)
    {
        $i = 1;
        while ($i < 50)
        {
            $showDataArr[$betsGame][$i]['rate'] = $rs->f[$rateIdx . d2($i)] - 0;
            ++$i;
        }
    }
    else
    {
        $rsu = get_srates_data($userid, $lotto_id, 25, $norder);
        $i = 1;
        while ($i < 50)
        {
            $showDataArr[$betsGame][$i]['rate'] = $rs->f[$rateIdx . d2($i)] - $rsu->f["r" . d2($i)] - 0;
            ++$i;
        }
        $rsu->close();
    }
    $rs->close();
}
if (isset($showDataArr[$betsGame]) && 0 < $dataTotalArr[$betsGame]['amount'])
{
    asort($lostwin[$betsGame]);
    reset($lostwin[$betsGame]);
    $k = 1;
    $showDataArrTemp = array();
    foreach ($lostwin[$betsGame] as $key => $val)
    {
        $showDataArrTemp[$betsGame][$k] = $showDataArr[$betsGame][$key];
        ++$k;
    }
    $showDataArr[$betsGame] = $showDataArrTemp[$betsGame];
}
$bettype = $betsGame;
$list = "";
$j = 1;
while ($j <= 10)
{
    $i = 0;
    while ($i < 5)
    {
        if ($i == 0)
        {
            $list .= "<tr class=td2 align=right>";
        }
        $k = $i * 10 + $j;
        if (49 < $k)
        {
            $list .= "<td></td><td></td><td></td><td></td><td></td>";
        }
        else
        {
            $numer = $showDataArr[$bettype][$k]['numbers'];
            $list .= "<td class=td6 align=center><font color=" . $colors[$g_numcolor[$numer]] . "><b>" . d2($numer) . "</b></font></td>";
            if (0 < $showDataArr[$bettype][$k]['totalnum'])
            {
                $list .= "<td nowrap>" . $showDataArr[$bettype][$k]['totalnum'] . "</td>";
                $list .= "<td nowrap " . $showDataArr[$bettype][$k]['namount'] . "><a href=" . get_listurl4($open, $listbetmod, $norder, d2($numer)) . ">" . round($showDataArr[$bettype][$k]['amount']) . "</a></td>";
            }
            else
            {
                $list .= "<td nowrap> 0</td>";
                $list .= "<td nowrap> 0</td>";
            }
            $list .= "<td nowrap> " . sprintf("%.2f", $showDataArr[$bettype][$k]['rate']) . "</td>";
            $list .= "<td nowrap>";
            if ($showDataArr[$bettype][$k]['winlost'] < 0)
            {
                $list .= "<font color='#EE2200'>" . round($showDataArr[$bettype][$k]['winlost']) . "</font></td>";
            }
            else
            {
                $list .= "<font color='#00AA22'>" . round($showDataArr[$bettype][$k]['winlost']) . "</font></td>";
            }
        }
        ++$i;
    }
    ++$j;
}
$mnuArr = array(1 => "正码一", 2 => "正码二", 3 => "正码三", 4 => "正码四", 5 => "正码五", 6 => "正码六");
$smenu = "";
$i = 1;
while ($i <= 6)
{
    if (1 < $i)
    {
        $smenu .= "｜";
    }
    if ($norder == $i)
    {
        $smenu .= "<font color=\"#800000\"><b>" . $mnuArr[$i] . "</b></font>";
    }
    else
    {
        $smenu .= "<a href=\"op.php?op=agent&fp=onlinebet4&lotto_id={$lotto_id}&norder={$i}&split={$split}&disk={$disk}&select={$selectid}\">" . $mnuArr[$i] . "</a>";
    }
    ++$i;
}
$tpl->set("sub_menu", $smenu);
$prate_list = "<td nowrap>赔率</td>";
$tpl->set("prate_table", $prate_list);
$tpl->set("list", $list);
$tpl->set("total", round($dataTotalArr[$bettype]['amount']));
$tpl->set("sum_count", intval($dataTotalArr[$bettype]['totalnum']));
$tpl->load("main", "onlinebet4.htm");
$tpl->show("main");
$ui->footer();
?>